<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'reply-edit', //页面标示
    'pagename' => '编辑自定义回复', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate'),
    'head' => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
      <!---->
      <div class="block">
          <a class="btn btn-default" href="<?php echo U('reply/add');?>">添加回复</a>
          <div class="btn-group" style="margin-left:20px">
              <a class="btn btn-white" href="<?php echo U('reply/follow');?>">关注自动回复</a>
              <a class="btn btn-white" href="<?php echo U('reply/index');?>">关键词回复</a>
          </div>
      </div>
      <!---->
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="Form1">
            <!---->
             <div class="form-group">
                <label class="col-sm-1 control-label">回复关键字</label>
                <div class="col-sm-3">
                  <input type="text" name="keyword" id="keyword" placeholder="" class="form-control" value="<?php echo $rs['keyword'];?>" />
                  <span class="help-block">不能长于64个字符，多个同义关键字用“|”隔开</span></div>
              </div>
              <!---->
              <div class="form-group">
                <label class="col-sm-1 control-label">匹配模式</label>
                <div class="col-sm-5">
                  <div class="row">
                    <div class="col-xs-3 radio m-l-large">
                      <label class="radio-custom">
                        <input type="radio" name="match_type"  value="0"  <?php if ($rs['match_type']==0){echo 'checked';}?>/>
                        <i class="fa fa-circle-o  <?php if ($rs['match_type']==0){echo 'checked';}?>"></i><span class="red">完全匹配</span></label>
                    </div>
                    <div class="col-xs-3 radio m-l-large">
                      <label class="radio-custom">
                        <input name="match_type" type="radio" value="1"  <?php if ($rs['match_type']==1){echo 'checked';}?>/>
                        <i class="fa fa-circle-o  <?php if ($rs['match_type']==1){echo 'checked';}?>"></i>模糊匹配</label>
                    </div>
                  </div>
                  <span class="help-block"></span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">回复类型</label>
                <div class="col-sm-10">
                  <div class="row">
                    <?php
						$showType=0;
						foreach($replyType as $key=>$val){
					?>
                    <div class="col-xs-1 radio m-l-large select_no_result_type">
                      <label class="radio-custom">
                        <input type="radio" name="reply_type" value="<?php echo $key;?>" <?php if ($rs['reply_type']==$key){echo 'checked';}?>/>
                        <i class="fa fa-circle-o <?php if ($rs['reply_type']==$key){echo 'checked';};?>"></i><?php echo $val;?></label>
                    </div>
                    <?php
						}
					?>
                  </div>
                  <p class="help-block"></p>
                </div>
              </div>
              <!--回复内容-->
              <div class="form-group item_no_result_type" <?php if ($rs['reply_type']!=0){echo 'style="display:none"';}?>>
                <label class="col-sm-1 control-label">回复内容</label>
                <div class="col-sm-8">
                  <p><a href="<?php echo U('face/index',array('id'=>'reply-content'));?>" rel="pop">添加表情</a></p>
                  <textarea class="form-control" id="reply-content" name="content"  style="height:200px"><?php echo $rs['content'];?></textarea>
                  <p class="help-block">文本内容支持html代码（A标签）</p>
                </div>
              </div>
              <!--图文列表-->
              <div class="form-group item_no_result_type"  <?php if ($rs['reply_type']!=1){echo 'style="display:none"';}?>>
                <label class="col-sm-1 control-label">图文列表</label>
                <div class="col-sm-4">
                  <select name="fid" class="form-control" id="fid">
                    <?php
					  if ($news){
						  foreach($news as $val){
					  ?>
                    <option value="<?php echo $val['id'];?>"  <?php if ($rs['reply_type']==1&&$rs['fid']==$val['id']){echo 'selected';}?>><?php echo $val['title'].'['.$newsType[$val['type']].']';?></option>
                    <?php
						}
					}else{
						echo '<option value="0">请先添加图文素材</option>';	
					}
					?>
                  </select>
                  <p class="help-block">只会显示最新20条</p>
                </div>
              </div>
              <!--回复动作-->
              <div class="form-group item_no_result_type" <?php if ($rs['reply_type']!=2){echo 'style="display:none"';}?>>
                <label class="col-sm-1 control-label">动作列表</label>
                <div class="col-sm-4">
                  <select name="action_id" class="form-control" id="action_id">
                    <?php
					if ($action){
						foreach($action as $key=>$val){
					?>
                    <option value="<?php echo $key;?>"  <?php if ($rs['reply_type']==2&&$rs['fid']==$key){echo 'selected';}?>><?php echo $val;?></option>
                    <?php
						}
					}else{
						echo '<option value="0">请先添加动作</option>';	
					}
					?>
                  </select>
                  <p class="help-block"></p>
                </div>
              </div>
              <!---->
              <div class="form-group">
                <label class="col-sm-1 control-label">状态</label>
                <div class="col-sm-5">
                  <div class="row">
                    <div class="col-xs-2 radio m-l-large">
                      <label class="radio-custom">
                        <input type="radio" name="status"  value="1"  <?php if ($rs['status']==1){echo 'checked';}?>/>
                        <i class="fa fa-circle-o  <?php if ($rs['status']==1){echo 'checked';}?>"></i><span class="red">正常</span></label>
                    </div>
                    <div class="col-xs-2 radio m-l-large">
                      <label class="radio-custom">
                        <input name="status" type="radio" value="0"  <?php if ($rs['status']==0){echo 'checked';}?>/>
                        <i class="fa fa-circle-o <?php if ($rs['status']==0){echo 'checked';}?>"></i>受限</label>
                    </div>
                  </div>
                  <span class="help-block"></span></div>
              </div>
              <!---->
              <input name="id" type="hidden" value="<?php echo $rs['id'];?>">
              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<script>
    $(function() {
		$('.select_no_result_type').click(function(){
			$('.item_no_result_type').hide().eq($(this).index()).show();
		})
        $("#Form1").submit(function() {
			if (!$("#keyword").val()){
				Msg.error('关键字不能为空');
				resetSubmit("#sub-ok",'保存');
				return false;
			}
			Msg.loading();
            $.post('<?php echo U('reply/save') ?>', $(this).serialize(), function(result) {
				Msg.hide();
				resetSubmit("#sub-ok",'保存');
                if (result.status == 1) {
					history.go(-1);
                    //document.location='<?php echo U('reply/index');?>';
                } else {
                    Msg.error(result.info);
                }
            }, "json");
            return false;
        })
    })
</script>
<?php
include getTpl('footer', 'public');
?>
